<template>
    <div class="msg-box in" :style="{ top: top + 'px' }">
        <div class="icon" v-if="icon != ''">
            <i class="iconfont" :class="icons[icon]"></i>
        </div>
        <div class="desc">
            <p class="title">{{ msg }}</p>
            <p v-if="info != ''">{{ info }}</p>
        </div>
        <div class="btn">
            <i class="iconfont icon-close2"></i>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            // msg: "默认值",
            // info:"默认值",
            icons: {
                success: "icon-success1",
                info: "icon-info",
                warning: "icon-warning",
                error: "icon-error",
                question: "icon-question"
            },
            // icon:"",
            // top:""
        }
    },
    props:{
        msg:{
            type:String,
            default:""
        },
        info:{
            type:String,
            default:""
        },
        icon:{
            type:String,
            default:""
        },
        top:{
            type:Number,
            default:0
        }
    }
}
</script>

<style>
@keyframes moveIn {
    0% {
        transform: translate(100%, 0);
        right: -6px;
    }

    100% {
        transform: translate(0%, 0);
        right: 10px;
    }
}

@keyframes moveOut {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}
</style>

<style lang="scss" scoped>
.msg-box {
    /*相对于最近的一个非静态元素进行定位，如果没有相对于body进行定位*/
    /* position: absolute; */
    position: fixed;
    background-color: white;
    top: 10px;
    right: 10px;
    box-shadow: 0 0 4px #666;
    border-radius: 6px;
    width: 300px;
    padding: 12px;
    display: flex;
    flex-flow: row nowrap;
    line-height: 20px;
    /*  */
    opacity: 1;
    transform: translate(0%, 0);
    transition: top ease 200ms;
    z-index: 9999;
}

.msg-box.in {
    animation: moveIn ease 400ms forwards;
}

.msg-box.out {
    animation: moveOut ease 200ms forwards;
}

.msg-box p {
    margin: 0px;
}

.msg-box .icon,
.msg-box .btn {
    width: 24px;
    /* font-size: 20px; */
    text-align: center;
}

.msg-box .btn .iconfont {
    font-size: 12px;
}

.msg-box .desc {
    font-size: 14px;
    flex-grow: 1;
    padding: 0px 4px;
    font-weight: bold;
}

.msg-box .icon .iconfont {
    font-size: 18px;
    color: #67c23a;
}

.msg-box .icon .icon-success1 {
    color: #67c23a;
}

.msg-box .icon .icon-info {
    color: #909399;
}

.msg-box .icon .icon-warning {
    color: #e6a23c;
}

.msg-box .icon .icon-error {
    color: #f56c6c;
}

.msg-box .icon .icon-question {
    color: #409eff;
}
</style>